console.log("??");

function brandNewOneFunc(urlpath,param){//前后端数据交互,ajax
			$.ajax({
				url:urlpath,
				datatype:"json",
				type:"post",
				data:param,
				success:function(data){
					 result=data;
					 showReservationInfo(data[0]);//自习室表格信息的分页显示
					pageNav();
				}
			})
		}
		var op="queryByPage";
		var array={"op":op};
		brandNewOneFunc("ReservationManageServlet",array);//自习室信息初始化

		function pageNav(){
			layui.use('laypage', function(){
				  var laypage = layui.laypage;
				  //执行一个laypage实例
				  laypage.render({
				    elem: 'pagediv' //注意，这里的 test1 是 ID，不用加 # 号
				    ,count: result[1].totalCount //数据总数，从服务端得到
				    ,curr:   result[1].page
				    ,limit:   result[1].pageSize
				    ,layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
				  ,jump: function(obj, first){
					    page=obj.curr;
					    pageSize=obj.limit;
					    if(!first){
					      //do something
					       var array={"op":"queryByPage","page":obj.curr,"pageSize":obj.limit};
					       brandNewOneFunc("StudyRoomManageServlet",array);
					      }
				    }
				  });
				});
		}

			    $(function () {

			        let form = layui.form
			            ,laydate = layui.laydate,
			            laypage = layui.laypage,
			            layer = layui.layer,
			            table = layui.table;
			        
			        $('body').on("click",".btn-reject",function () {
				         var pre = $(this);
				         layui.layer.confirm('确定要拒绝此预约吗？',{
				                btn:['确定','取消']
				        },function () {
				        	layui.layer.closeAll('dialog');
				        	var op="rejectReservation";
							var Resid=$(pre).parent().parent().find("td").children().eq(0).val();
							var array={"Resid":Resid,"op":op,"page":page,"pageSize":pageSize};
							brandNewOneFunc("ReservationManageServlet",array);		            
				        })
				    });
			        
			        $('body').on("click",".btn-accept",function () {
				         var pre = $(this);
				         layui.layer.confirm('确定要接受此预约吗？',{
				                btn:['确定','取消']
				        },function () {
				        	layui.layer.closeAll('dialog');
				        	var op="acceptReservation";
							var Resid=$(pre).parent().parent().find("td").children().eq(0).val();
							var array={"Resid":Resid,"op":op,"page":page,"pageSize":pageSize};
							brandNewOneFunc("ReservationManageServlet",array);		            
				        })
				    });
			        
			    });

		//查询预约信息
		function searchReservation(){
				   var   keywords=document.getElementById("searchContent").value;
				    var array={"op":"queryByPage","page":page,"pageSize":pageSize,"keywords":keywords};
				    brandNewOneFunc("ReservationManageServlet",array);
		}
		

function showReservationInfo(jsonstr){//显示表格数据
	console.log("调用showReservationInfo");
	var data = jsonstr;
	document.getElementById("tbody1").innerHTML="";
	var HTML ="";
		if(data!=null)
		{
			for(var i=0;i<data.length;i++){
			 HTML += '<tr>\n' +
             '                            <td >\n' +
             '                                <input class="layui-input" name="Resid"  readonly="readonly" value="'+data[i].Resid+'">\n' +
             '                            </td>\n' +
             '                            <td>\n' +
             ' 										<input class="layui-input" name="Userid"  readonly="readonly" value="'+data[i].Userid+'">\n' +
             '                            </td>\n' +
             '                            <td>\n' +
             ' 										<input class="layui-input" name="UserCredibility"  readonly="readonly" value="'+data[i].UserCredibility+'">\n' +
             '                            </td>\n' +
             '                            <td>\n' +
             '                                <input type="text" name="Eseatno" class="layui-input" readonly="readonly" value="'+data[i].Eseatno+'">\n' +
             '                            </td>\n' +
             '                            <td>\n' +
             '                                <input type="text" name="Restatus" class="layui-input" readonly="readonly" value="'+data[i].Restatus+'">\n' +
             '                            </td>\n' +
             '                            <td>\n' +
             '                                <input type="text"  name="Restime" class="layui-input" placeholder="yyyy-MM-dd-ss"  readonly="readonly" value="'+data[i].Restime+'">\n' +
             '                            </td>\n' +
             '                            <td>\n' +
             '                                <input type="text" name="Resetime" class="layui-input" placeholder="yyyy-MM-dd-ss"  readonly="readonly" value="'+data[i].Resetime+'">\n' +
             '                            </td>\n' +
             '                            <td style="text-align: center" ><button type="button" class="layui-btn layui-btn-danger btn-reject" " >拒绝</button>\n' +
             '                            <button type="button" class="layui-btn layui-btn-danger btn-accept" >通过</button></td>\n' +
             '                        </tr>';
			  }

			document.getElementById("tbody1").innerHTML=HTML;
       }
}
